home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / gcc263-src.lha / gcc-2.6.3 / config / i386 / sol2-c1.asm < prev    next >
Assembly Source File  |  1993-02-05  |  5KB  |  156 lines

  1. ! crt1.s for Solaris 2, x86
  2.  
  3. !   Copyright (C) 1993 Free Software Foundation, Inc.
  4. !   Written By Fred Fish, Nov 1992
  5. ! This file is free software; you can redistribute it and/or modify it
  6. ! under the terms of the GNU General Public License as published by the
  7. ! Free Software Foundation; either version 2, or (at your option) any
  8. ! later version.
  9. ! In addition to the permissions in the GNU General Public License, the
  10. ! Free Software Foundation gives you unlimited permission to link the
  11. ! compiled version of this file with other programs, and to distribute
  12. ! those programs without any restriction coming from the use of this
  13. ! file.  (The General Public License restrictions do apply in other
  14. ! respects; for example, they cover modification of the file, and
  15. ! distribution when not linked into another program.)
  16. ! This file is distributed in the hope that it will be useful, but
  17. ! WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19. ! General Public License for more details.
  20. ! You should have received a copy of the GNU General Public License
  21. ! along with this program; see the file COPYING.  If not, write to
  22. ! the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23. !    As a special exception, if you link this library with files
  24. !    compiled with GCC to produce an executable, this does not cause
  25. !    the resulting executable to be covered by the GNU General Public License.
  26. !    This exception does not however invalidate any other reasons why
  27. !    the executable file might be covered by the GNU General Public License.
  28.  
  29. ! This file takes control of the process from the kernel, as specified
  30. ! in section 3 of the System V Application Binary Interface, Intel386
  31. ! Processor Supplement.  It has been constructed from information obtained
  32. ! from the ABI, information obtained from single stepping existing
  33. ! Solaris executables through their startup code with gdb, and from
  34. ! information obtained by single stepping executables on other i386 SVR4
  35. ! implementations.  This file is the first thing linked into any executable.
  36.  
  37.     .file    "crt1.s"
  38.     .ident    "GNU C crt1.s"
  39.     .weak    _cleanup
  40.     .weak    _DYNAMIC
  41.     .text
  42.  
  43. ! Start creating the initial frame by pushing a NULL value for the return
  44. ! address of the initial frame, and mark the end of the stack frame chain
  45. ! (the innermost stack frame) with a NULL value, per page 3-32 of the ABI.
  46. ! Initialize the first stack frame pointer in %ebp (the contents of which
  47. ! are unspecified at process initialization).
  48.  
  49.     .globl    _start
  50. _start:
  51.     pushl    $0x0
  52.     pushl    $0x0
  53.     movl    %esp,%ebp
  54.  
  55. ! As specified per page 3-32 of the ABI, %edx contains a function 
  56. ! pointer that should be registered with atexit(), for proper
  57. ! shared object termination.  Just push it onto the stack for now
  58. ! to preserve it.  We want to register _cleanup() first.
  59.  
  60.     pushl    %edx
  61.  
  62. ! Check to see if there is an _cleanup() function linked in, and if
  63. ! so, register it with atexit() as the last thing to be run by
  64. ! atexit().
  65.  
  66.     movl    $_cleanup,%eax
  67.     testl    %eax,%eax
  68.     je    .L1
  69.     pushl    $_cleanup
  70.     call    atexit
  71.     addl    $0x4,%esp
  72. .L1:
  73.  
  74. ! Now check to see if we have an _DYNAMIC table, and if so then
  75. ! we need to register the function pointer previously in %edx, but
  76. ! now conveniently saved on the stack as the argument to pass to
  77. ! atexit().
  78.  
  79.     movl    $_DYNAMIC,%eax
  80.     testl    %eax,%eax
  81.     je    .L2
  82.     call    atexit
  83. .L2:
  84.  
  85. ! Register _fini() with atexit().  We will take care of calling _init()
  86. ! directly.
  87.  
  88.     pushl    $_fini
  89.     call    atexit
  90.  
  91. ! Compute the address of the environment vector on the stack and load
  92. ! it into the global variable _environ.  Currently argc is at 8 off
  93. ! the frame pointer.  Fetch the argument count into %eax, scale by the
  94. ! size of each arg (4 bytes) and compute the address of the environment
  95. ! vector which is 16 bytes (the two zero words we pushed, plus argc,
  96. ! plus the null word terminating the arg vector) further up the stack,
  97. ! off the frame pointer (whew!).
  98.  
  99.     movl    8(%ebp),%eax
  100.     leal    16(%ebp,%eax,4),%edx
  101.     movl    %edx,_environ
  102.  
  103. ! Push the environment vector pointer, the argument vector pointer,
  104. ! and the argument count on to the stack to set up the arguments
  105. ! for _init(), _fpstart(), and main().  Note that the environment
  106. ! vector pointer and the arg count were previously loaded into
  107. ! %edx and %eax respectively.  The only new value we need to compute
  108. ! is the argument vector pointer, which is at a fixed address off
  109. ! the initial frame pointer.
  110.  
  111.     pushl    %edx
  112.     leal    12(%ebp),%edx
  113.     pushl    %edx
  114.     pushl    %eax
  115.  
  116. ! Call _init(argc, argv, environ), _fpstart(argc, argv, environ), and
  117. ! main(argc, argv, environ).
  118.  
  119.     call    _init
  120.     call    __fpstart
  121.     call    main
  122.  
  123. ! Pop the argc, argv, and environ arguments off the stack, push the
  124. ! value returned from main(), and call exit().
  125.  
  126.     addl    $12,%esp
  127.     pushl    %eax
  128.     call    exit
  129.  
  130. ! An inline equivalent of _exit, as specified in Figure 3-26 of the ABI.
  131.  
  132.     pushl    $0x0
  133.     movl    $0x1,%eax
  134.     lcall    $7,$0
  135.  
  136. ! If all else fails, just try a halt!
  137.  
  138.     hlt
  139.     .type    _start,@function
  140.     .size    _start,.-_start
  141.  
  142. ! A dummy profiling support routine for non-profiling executables,
  143. ! in case we link in some objects that have been compiled for profiling.
  144.  
  145.     .globl    _mcount
  146. _mcount:
  147.     ret
  148.     .type    _mcount,@function
  149.     .size    _mcount,.-_mcount
  150.